package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodSalesDTO;
import com.sky.dto.order.OrderSelectDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * @Author 褚金龙
 * @Date 2024/10/6 10:35
 */
@Mapper
public interface OrderMapper {

    /**
     * 向订单表里插入一条数据
     * @param orders
     */
    void insert(Orders orders);


    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where user_id=#{userId} and number = #{orderNumber}"  )
    Orders getByNumber(String orderNumber,Long userId);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    /**
     * 根据订单编号删除订单
     * @param orderNumber
     */
    @Delete("delete from orders where number=#{orderNumber}")
    void delete(String orderNumber);


    /**
     * 修改订单
     * @param orderStatus
     * @param orderPaidStatus
     * @param checkOutTime
     * @param orderNumber
     */
    @Update("update orders  set  status=#{orderStatus},pay_status=#{orderPaidStatus} ,checkout_Time=#{checkOutTime},number=#{orderNumber} ")
    void updateStatus(Integer orderStatus, Integer orderPaidStatus, LocalDateTime checkOutTime, String orderNumber);

    @Select("select * from orders where status=#{status} and order_time < #{orderTime}")
    List<Orders> getByStatusAndOrderTimeLT(Integer status, LocalDateTime orderTime);




    /**
     * 管理端查询订单数据
     * @param orderSelectDTO
     * @return
     */
    Page<Orders> select(OrderSelectDTO orderSelectDTO);

    /**
     * 根据id删除订单
     * @param id
     */
    @Delete("delete from orders where id=#{id}")
    void remove(Long id);

    @Select("select * from orders where id=#{id}")
    Orders getById(Long id);

    /**
     * 根据动态条件统计营业额数据
     * @param map
     * @return
     */
    Double sumByMap(Map map);




    /**
     * 统计订单数据
     * @param map
     * @return
     */
    Integer countByMap(Map map);


    /**
     * 查询菜品排名top10
     * @param map
     * @return
     */
    List<GoodSalesDTO> getSalesTop10(Map map);
}
